package com.funmi.lizip.controller;

import com.alibaba.fastjson.JSONObject;
import com.funmi.lizip.common.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.Objects;

@Api(tags = "首页模块")
@RestController
public class IndexController {

    @ApiImplicitParam(name = "name",value = "姓名",dataTypeClass = String.class, required = true)
    @ApiOperation(value = "向客人问好")
    @GetMapping("/sayHi")
    public ResponseEntity<String> sayHi(@RequestParam(value = "name")String name){
        //language=JSON
        String json = "[{\"id\":\"1\",\"name\":\"名字\"},\n" +
                "  {\"id\":\"6\",\"name\":\"姓名\"}\n" +
                "]";
        Map<Integer, String> map = JSONObject.parseArray(json).toJavaList(JSONObject.class)
                .stream().filter(Objects::nonNull).collect(Collectors.toMap(
                item -> item.getInteger("id"),
                item -> item.getString("name")));
        map.forEach((id, name1) ->{
            System.out.println(id +  name1);
        });

        return ResponseEntity.ok("Hi:"+name);
    }






}